package com.example.UI;

import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.widget.PopupWindow;
import android.widget.ScrollView;

/**
 * Created by Administrator on 2017/1/11.
 */

public class MyScrollview extends ScrollView {
    private PopupWindow window;
    private boolean dismiss = false;
    public MyScrollview(Context context) {
        super(context);
    }
    public void setWindow(PopupWindow window){
        this.window = window;
    }

    public MyScrollview(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public MyScrollview(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    public boolean onTouchEvent(MotionEvent ev) {
        switch (ev.getAction())
        {
            case MotionEvent.ACTION_DOWN:
                dismiss = true;
                break;
            case MotionEvent.ACTION_MOVE:
                dismiss = false;
                break;
            case MotionEvent.ACTION_UP:
                if(dismiss == true){
                    window.dismiss();
                }
                break;
            case MotionEvent.ACTION_CANCEL:
                break;


        }
        return super.onTouchEvent(ev);
    }
}
